package com.kpy.consumer.controller;

import com.kpy.consumer.model.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @auther: kpy
 * @version: 1.0
 * @Package: com.kpy.consumer.controller
 * @data: 2022-3-1 9:46
 * @discription:
 **/

@RestController
public class ConsumerController {

    private RestTemplate restTemplate;

    public ConsumerController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping("/user/{id}")
    public User findById(@PathVariable long id){
        System.out.println("id="+id);
        return this.restTemplate.getForObject("http://provider/"+id, User.class);
    }

}
